const { list, deleteRecord } = require('./data/free-files-items')

const base = '/movieserver'

module.exports = [{
  url: `${base}/freeFiles/[a-zA-Z]+`,
  type: 'get',
  response: config => {
    const result = config.url.match(/freeFiles\/(?<type>[a-zA-Z]+)/)
    const { page, limit } = config.query
    console.log('page=' + page + ',limit=' + limit + ',type=' + result.groups.type)
    return list(page, limit, result.groups.type)
  }
}, {
  url: `${base}/freeFiles/[a-zA-Z]+/[1-9][0-9]*`,
  type: 'delete',
  response: config => {
    const id = config.url.match(/[1-9][0-9]*/)
    deleteRecord(id)
    return { success: true }
  }
}]
